package com.yildiz.ara.geomedikal;

import java.util.ArrayList;
import android.app.ActivityGroup;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

public class EczaneGroup extends ActivityGroup  {
	
	public static EczaneGroup group;
	private ArrayList<View> history;
	public static EczaneGroup getGroup() {
		return group;
	}

	public static void setGroup(EczaneGroup group) {
		EczaneGroup.group = group;
	}
	
	View view;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		history = new ArrayList<View>();
		this.setHistory(history);
//		Log.d("COHOUS", "ListGroup-> onCreate");
		group = this;

		// Start the root activity withing the group and get its view
		view = getLocalActivityManager().startActivity(
				"Eczane-1",
				new Intent(this, Eczane1.class)
						.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
				.getDecorView();

		// Replace the view of this ActivityGroup
		replaceView(view);

	}

	public void replaceView(View v) {
		// Adds the old one to history
//		Log.d("COHOUS", "ListGroup-> replaceView");
		getHistory().add(v);
		// Changes this Groups View to the new View.
		setContentView(v);

	}

	public void back() {
//		Log.d("COHOUS", "ListGroup-> back()");
		if (getHistory().size() > 0) {
			if(getHistory().size() == 2){
//				Log.v("COHOUS","2 VIEW VAR ARRAY LISTTE");
				getHistory().clear();
				view = getLocalActivityManager().startActivity(
						"Eczane-1",
						new Intent(this, Eczane1.class)
								.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
						.getDecorView();
				replaceView(view);
//				Log.v("COHOUS","2 VIEW VAR ARRAY LISTTE");
			}else{
//				Log.v("COHOUS","1 VIEW VAR ARRAY LISTTE");
				finish();
			}
		} else {
//			Log.v("COHOUS","ZZZZZZZZZZZZZZZZZZZZZZZZZZZ");
			finish();
		}
	}

	@Override
	public void onBackPressed() {
//		Log.d("COHOUS", "ListGroup-> onBackPressed");
		EczaneGroup.group.back();
		return;
	}

	public ArrayList<View> getHistory() {
//		Log.d("COHOUS", "ListGroup-> getHistory");
		return history;
	}

	public void setHistory(ArrayList<View> history) {
//		Log.d("COHOUS", "ListGroup-> setHistory");
		this.history = history;
	}
}
